// Toast 工具类
export class Toast {
  static show(message, options = {}) {
    const {
      duration = 3000,
      type = 'info', // info, success, error, warning
      position = 'top-center' // top-right, top-left, bottom-right, bottom-left, top-center, bottom-center
    } = options;

    // 创建 toast 元素
    const toast = document.createElement('div');
    toast.className = `toast-message ${type} ${position}`;
    toast.textContent = message;

    // 添加样式
    const style = document.createElement('style');
    style.textContent = `
      .toast-message {
        position: fixed;
        padding: 6px 12px;
        border-radius: 4px;
        color: white;
        font-size: 14px;
        z-index: 10000;
        box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
      }

      .toast-message.info {
        background-color: #2196F3;
      }

      .toast-message.success {
        background-color: #4CAF50;
      }

      .toast-message.error {
        background-color: #F44336;
      }

      .toast-message.warning {
        background-color: #FFC107;
      }

      .toast-message.top-right {
        top: 20px;
        right: 20px;
      }

      .toast-message.top-left {
        top: 20px;
        left: 20px;
      }

      .toast-message.bottom-right {
        bottom: 20px;
        right: 20px;
      }

      .toast-message.bottom-left {
        bottom: 20px;
        left: 20px;
      }

      .toast-message.top-center {
        top: 20px;
        left: 50%;
        transform: translateX(-50%);
      }

      .toast-message.bottom-center {
        bottom: 20px;
        left: 50%;
        transform: translateX(-50%);
      }

      @keyframes toast-in {
        from {
          transform: translateY(20px);
          opacity: 0;
        }
        to {
          transform: translateY(0);
          opacity: 1;
        }
      }

      @keyframes toast-out {
        from {
          transform: translateY(0);
          opacity: 1;
        }
        to {
          transform: translateY(-20px);
          opacity: 0;
        }
      }
    `;

    document.head.appendChild(style);
    document.body.appendChild(toast);

    // 定时移除
    setTimeout(() => {
      toast.remove();
      style.remove();
    }, duration);

    return toast;
  }

  // 快捷方法
  static success(message, duration) {
    return this.show(message, { type: 'success', duration });
  }

  static error(message, duration) {
    return this.show(message, { type: 'error', duration,position:'bottom-center' });
  }

  static warning(message, duration) {
    return this.show(message, { type: 'warning', duration,position:'bottom-center' });
  }

  static info(message, duration) {
    return this.show(message, { type: 'info', duration });
  }
}